package com.itheima.project.web;


import org.springframework.web.bind.annotation.RequestMapping;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.project.basic.ResponseWrap;
import com.itheima.project.core.enums.content.ContentBaseRuleEnum;
import com.itheima.project.face.ContentBaseRuleFace;
import com.itheima.project.utils.ResponseWrapBuild;
import com.itheima.project.vo.content.ContentBaseRuleVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import org.springframework.web.bind.annotation.RestController;

/**
 * @Description：前端控制器
 */
@Slf4j
@Api(tags = "controller")
@RestController
@RequestMapping("content-base-rule")
public class ContentBaseRuleController {

    @Autowired
    ContentBaseRuleFace contentBaseRuleFace;

    /***
     * @description 多条件查询分页列表
     * @param contentBaseRuleVo Vo查询条件
     * @param pageNum 页码
     * @param pageSize 每页条数
     * @return: Page<ContentBaseRuleVo>
     */
    @PostMapping("page/{pageNum}/{pageSize}")
    @ApiOperation(value = "分页",notes = "分页")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "contentBaseRuleVo",value = "Vo对象",required = true,dataType = "ContentBaseRuleVo"),
        @ApiImplicitParam(paramType = "path",name = "pageNum",value = "页码",example = "1",dataType = "Integer"),
        @ApiImplicitParam(paramType = "path",name = "pageSize",value = "每页条数",example = "10",dataType = "Integer")
    })
    public ResponseWrap<Page<ContentBaseRuleVo>> findContentBaseRuleVoPage(
                                    @RequestBody ContentBaseRuleVo contentBaseRuleVo,
                                    @PathVariable("pageNum") int pageNum,
                                    @PathVariable("pageSize") int pageSize) {
        Page<ContentBaseRuleVo> contentBaseRuleVoPage = contentBaseRuleFace.findContentBaseRuleVoPage(contentBaseRuleVo, pageNum, pageSize);
        return ResponseWrapBuild.build(ContentBaseRuleEnum.SUCCEED,contentBaseRuleVoPage);
    }

    /**
     * @Description 保存
     * @param contentBaseRuleVo Vo对象
     * @return ContentBaseRuleVo
     */
    @PutMapping
    @ApiOperation(value = "添加ContentBaseRule",notes = "添加ContentBaseRule")
    @ApiImplicitParam(name = "contentBaseRuleVo",value = "Vo对象",required = true,dataType = "ContentBaseRuleVo")
    public ResponseWrap<ContentBaseRuleVo> createContentBaseRule(@RequestBody ContentBaseRuleVo contentBaseRuleVo) {
        ContentBaseRuleVo contentBaseRuleVoResult = contentBaseRuleFace.createContentBaseRuleVo(contentBaseRuleVo);
        return ResponseWrapBuild.build(ContentBaseRuleEnum.SUCCEED,contentBaseRuleVoResult);
    }

    /**
     * @Description 修改
     * @param contentBaseRuleVo Vo对象
     * @return Boolean 是否修改成功
     */
    @PatchMapping
    @ApiOperation(value = "修改",notes = "修改")
    @ApiImplicitParam(name = "contentBaseRuleVo",value = "Vo对象",required = true,dataType = "ContentBaseRuleVo")
    public ResponseWrap<Boolean> updateContentBaseRule(@RequestBody ContentBaseRuleVo contentBaseRuleVo) {
        Boolean flag = contentBaseRuleFace.updateContentBaseRuleVo(contentBaseRuleVo);
        return ResponseWrapBuild.build(ContentBaseRuleEnum.SUCCEED,flag);
    }

    /**
     * @Description 删除
     * @param contentBaseRuleVo 刪除条件：checkedIds 不可为空
     * @return
     */
    @DeleteMapping
    @ApiOperation(value = "删除",notes = "删除")
    @ApiImplicitParam(name = "contentBaseRuleVo",value = "Vo对象",required = true,dataType = "ContentBaseRuleVo")
    public ResponseWrap<Boolean> deleteContentBaseRule(@RequestBody ContentBaseRuleVo contentBaseRuleVo) {
        Boolean flag = contentBaseRuleFace.deleteContentBaseRuleVo(contentBaseRuleVo.getCheckedIds());
        return ResponseWrapBuild.build(ContentBaseRuleEnum.SUCCEED,flag);
    }

    /***
     * @description 多条件查询列表
     * @param contentBaseRuleVo Vo对象
     * @return List<ContentBaseRuleVo>
     */
    @PostMapping("list")
    @ApiOperation(value = "多条件查询列表",notes = "多条件查询列表")
    @ApiImplicitParam(name = "contentBaseRuleVo",value = "Vo对象",required = true,dataType = "ContentBaseRuleVo")
    public ResponseWrap<List<ContentBaseRuleVo>> contentBaseRuleList(@RequestBody ContentBaseRuleVo contentBaseRuleVo) {
        List<ContentBaseRuleVo> contentBaseRuleVoList = contentBaseRuleFace.findContentBaseRuleVoList(contentBaseRuleVo);
        return ResponseWrapBuild.build(ContentBaseRuleEnum.SUCCEED,contentBaseRuleVoList);
    }

}
